﻿using System;
using System.Collections.Generic;

using Common.Base;

using GameCommon.Manager;

using Menu.Components;

namespace Menu.Screens.Background
{
    internal static class MenuBackgroundBuilder
    {
        public static IEnumerable<Texture> GetTiles()
        {
            var screenSize = Managers.ContentManager.GetViewportSize();
            var tileTexture = Managers.ContentManager.GetBoardTexture2D("FreeSpace", 1);

            var horizontalTiles = (screenSize.Width / tileTexture.Width) / 1.25;
            var verticalTiles = (screenSize.Height / (tileTexture.Height / 2)) * 1.25;

            var list = new List<Texture>();

            for (var y = 0; y < verticalTiles; y++)
            {
                for (var x = 0; x < horizontalTiles; x++)
                {
                    var id = string.Format("T_{0}_{1}", x, y);
                    var tex = new Texture(id, tileTexture);

                    int posX;
                    if (y % 2 == 0)
                    {
                        posX = (int)Math.Round(1.5 * x * tileTexture.Width);    
                    }
                    else
                    {
                        posX = (int)Math.Round((1.5 * x * tileTexture.Width) + (tileTexture.Width * 0.75));
                    }

                    var posY = (y * (tileTexture.Height / 2)) - (y * 4);

                    tex.Dimension.Position = new Position(posX, posY);
                    list.Add(tex);
                }
            }

            return list;
        }
    }
}